package com.haizhi.crm.biz.task.message.handler;

import com.haizhi.crm.common.context.SpringContext;
import com.haizhi.crm.common.log.GLog;
import com.haizhi.crm.common.log.LogFactory;

/**
 * Created by wangshan on 2018/5/29.
 */
public class HandlerBuilder {

    private static final GLog LOG = LogFactory.getLogger(HandlerBuilder.class);

    private AbstractHandler head = null;
    private AbstractHandler tail = null;

    public HandlerBuilder add(Class<? extends AbstractHandler> handleClass) {
        AbstractHandler abstractHandler = SpringContext.getBean(handleClass);
        if (head == null) {
            head = abstractHandler;
            tail = abstractHandler;
        } else {
            tail.setNextHandler(abstractHandler);
            tail = abstractHandler;
        }
        return this;
    }

    public AbstractHandler get() {
        return head;
    }

    public static HandlerBuilder build() {
        return new HandlerBuilder();
    }

}
